package com.snowj.apaas.repository.auto;

import static com.snowj.apaas.repository.auto.UserGroupsDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.snowj.apaas.domain.auto.UserGroups;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface UserGroupsMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264724+08:00", comments="Source Table: user_groups")
    BasicColumn[] selectList = BasicColumn.columnList(id, groupName, parentId, manager);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.262677+08:00", comments="Source Table: user_groups")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.262715+08:00", comments="Source Table: user_groups")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.262759+08:00", comments="Source Table: user_groups")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    @Options(useGeneratedKeys=true,keyProperty="record.id")
    int insert(InsertStatementProvider<UserGroups> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.263365+08:00", comments="Source Table: user_groups")
    @Insert({
        "${insertStatement}"
    })
    @Options(useGeneratedKeys=true,keyProperty="records.id")
    int insertMultiple(@Param("insertStatement") String insertStatement, @Param("records") List<UserGroups> records);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264148+08:00", comments="Source Table: user_groups")
    default int insertMultiple(MultiRowInsertStatementProvider<UserGroups> multipleInsertStatement) {
        return insertMultiple(multipleInsertStatement.getInsertStatement(), multipleInsertStatement.getRecords());
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264209+08:00", comments="Source Table: user_groups")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("UserGroupsResult")
    Optional<UserGroups> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264258+08:00", comments="Source Table: user_groups")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="UserGroupsResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="group_name", property="groupName", jdbcType=JdbcType.VARCHAR),
        @Result(column="parent_id", property="parentId", jdbcType=JdbcType.BIGINT),
        @Result(column="manager", property="manager", jdbcType=JdbcType.VARCHAR)
    })
    List<UserGroups> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264333+08:00", comments="Source Table: user_groups")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.26439+08:00", comments="Source Table: user_groups")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, userGroups, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264426+08:00", comments="Source Table: user_groups")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, userGroups, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264461+08:00", comments="Source Table: user_groups")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264504+08:00", comments="Source Table: user_groups")
    default int insert(UserGroups record) {
        return MyBatis3Utils.insert(this::insert, record, userGroups, c ->
            c.map(groupName).toProperty("groupName")
            .map(parentId).toProperty("parentId")
            .map(manager).toProperty("manager")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264565+08:00", comments="Source Table: user_groups")
    default int insertMultiple(Collection<UserGroups> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, userGroups, c ->
            c.map(groupName).toProperty("groupName")
            .map(parentId).toProperty("parentId")
            .map(manager).toProperty("manager")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264633+08:00", comments="Source Table: user_groups")
    default int insertSelective(UserGroups record) {
        return MyBatis3Utils.insert(this::insert, record, userGroups, c ->
            c.map(groupName).toPropertyWhenPresent("groupName", record::getGroupName)
            .map(parentId).toPropertyWhenPresent("parentId", record::getParentId)
            .map(manager).toPropertyWhenPresent("manager", record::getManager)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264762+08:00", comments="Source Table: user_groups")
    default Optional<UserGroups> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, userGroups, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264808+08:00", comments="Source Table: user_groups")
    default List<UserGroups> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, userGroups, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264846+08:00", comments="Source Table: user_groups")
    default List<UserGroups> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, userGroups, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264889+08:00", comments="Source Table: user_groups")
    default Optional<UserGroups> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.264933+08:00", comments="Source Table: user_groups")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, userGroups, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.26497+08:00", comments="Source Table: user_groups")
    static UpdateDSL<UpdateModel> updateAllColumns(UserGroups record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(groupName).equalTo(record::getGroupName)
                .set(parentId).equalTo(record::getParentId)
                .set(manager).equalTo(record::getManager);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.265049+08:00", comments="Source Table: user_groups")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(UserGroups record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(groupName).equalToWhenPresent(record::getGroupName)
                .set(parentId).equalToWhenPresent(record::getParentId)
                .set(manager).equalToWhenPresent(record::getManager);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.265187+08:00", comments="Source Table: user_groups")
    default int updateByPrimaryKey(UserGroups record) {
        return update(c ->
            c.set(groupName).equalTo(record::getGroupName)
            .set(parentId).equalTo(record::getParentId)
            .set(manager).equalTo(record::getManager)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.265296+08:00", comments="Source Table: user_groups")
    default int updateByPrimaryKeySelective(UserGroups record) {
        return update(c ->
            c.set(groupName).equalToWhenPresent(record::getGroupName)
            .set(parentId).equalToWhenPresent(record::getParentId)
            .set(manager).equalToWhenPresent(record::getManager)
            .where(id, isEqualTo(record::getId))
        );
    }
}